/**
 * 
 */
package org.jenkon.validator;

/**
 * @author Jens Konopka
 * 
 * @param <T>
 */
public class OrValidator<T> extends AbstractConditionValidator<T> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4646697079474332736L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jenkon.validation.Validator#validate(java.lang.Object)
	 */
	public void validate(final T value) {
		if (!isValid(value)) {
			throw new ValidationException(value + " is not valid.");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jenkon.validation.AbstractValidator#isValid(java.lang.Object)
	 */
	public boolean isValid(final T value) {
		for (final Validator<T> validator : validators) {
			if (validator.isValid(value)) {
				return true;
			}
		}
		return false;
	}

}
